<template>
    <view>
        <view class="tui-actionsheet-class tui-actionsheet" :class="[show ? 'tui-actionsheet-show' : '']" style="bottom: 0;">
            <view class="container bh-row bh-justify-start bh-align-center">
                <textarea ref="textarea1" v-model="commentContent"
                    show-confirm-bar=""
                    :cursor-spacing=30
                 class="comment-text" placeholder="给对方留言" placeholder-class="textarea-placeholder" autofocus :focus="firstFocus" confirm-type="send" @input="changeComment" @confirm="confirmComment" />
                <view class="comment-btn" @click="confirmComment">留言</view>
            </view>
        </view>
        <view class="tui-actionsheet-mask" style="top:0" :class="[show ? 'tui-mask-show' : '']" @tap="closeModel" @touchend="closeModel"></view>
    </view>
</template>
 
<script>
export default {
    name: "showAddCommentSheet",
    emits: ['close', 'change', 'confirm',],
    props: {
        //显示操作菜单
        show: {
            type: Boolean,
            default: false
        },
        initValue: {
            type: String,
            default: ''
        }
    },
    data() {
        return {
            commentContent: '',
            firstFocus: false
        }
    },
    created() {
        this.commentContent = this.initValue

    },
    mounted() {
        // this.$nextTick(() => {
        //     this.$refs.textarea1.focus(); // 确保 ref 设置正确
        // });
        // this.$refs.textarea1.focus();
        // uni.$refs.textarea1.focus();
        // uni.$invoke('textarea', 'focus');
        console.log('使获得焦点', this.firstFocus)
    },
    methods: {
        focusInput() {
            console.log('自动获得焦点')
            this.firstFocus = true
        },
        closeModel() {
            this.firstFocus = false
            this.$emit('close')
        },
        changeComment(e) {
            console.log('改变留言的值', e)
            this.commentContent = e.detail.value
            this.$emit('change', e.detail.value)
        },
        confirmComment(e) {
            let comment = this.commentContent
            this.$emit('confirm', comment)
            this.commentContent = ''
        }
    }
}
</script>
 
<style scoped lang="scss">
@import url(../../static/css/base.css);

.tui-actionsheet {
    width: 100%;
    position: fixed;
    left: 0;
    right: 0;
    /* top: 0; */
    z-index: 9999;
    visibility: hidden;
    transform: translate3d(0, 100%, 0);
    transform-origin: center;
    transition: all 0.3s ease-in-out;
    background: #eaeaec;
    background: white;
    min-height: 100rpx;
    /* border-top-left-radius: 32rpx;
    border-top-right-radius: 32rpx; */
    // border-radius: 10rpx;
    box-shadow: 0px -2px 6px 0px rgba(0, 0, 0, 0.05);

    // box-shadow: 0px -4px 4px 0px rgba(0, 0, 0, 0.2);
}

.tui-actionsheet-show {
    transform: translate3d(0, 0, 0);
    visibility: visible;
}

.tui-tips {
    width: 100%;
    padding: 30rpx 60rpx;
    // box-sizing: border-box;
    text-align: center;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tui-operate-box {
    padding-bottom: 12rpx;
}

.tui-actionsheet-btn {
    width: 100%;
    height: 100rpx;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 36rpx;
    position: relative;
}

.tui-btn-last {
    padding-bottom: env(safe-area-inset-bottom);
}

.tui-actionsheet-divider::before {
    content: '';
    width: 100%;
    // border-top: 1rpx solid #d9d9d9;
    position: absolute;
    top: 0;
    left: 0;
    -webkit-transform: scaleY(0.5);
    transform: scaleY(0.5);
}

.tui-actionsheet-cancel {
    color: #1a1a1a;
    padding-bottom: env(safe-area-inset-bottom);
}

.tui-actionsheet-hover {
    background: #f7f7f9;
}

.tui-actionsheet-mask {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    // background: rgba(0, 0, 0, 0.6);
    background: rgba(0, 0, 0, 0.25);
    z-index: 9996;
    transition: all 0.3s ease-in-out;
    opacity: 0;
    visibility: hidden;
}

.tui-mask-show {
    opacity: 1;
    visibility: visible;
}

.container {
    // top: 546.02px;
    // width: 375px;
    // height: 265.98px;
    // margin-left: 32rpx;
    margin-right: 32rpx;
    margin-top: 24rpx;
    margin-bottom: 24rpx;
    // margin-bottom: 72rpx;
}

.textarea-placeholder {
    font-size: 28rpx;
    font-weight: normal;

    color: #999999;
}

.comment-text {
    height: 80rpx;
    background: #F5F6F6;
    margin-left: 32rpx;
    border-radius: 100px;
    display: block;
    flex: 1;
    padding-left: 32rpx;
    padding-top: 24rpx;
    margin-right: 24rpx;
}

.comment-btn {
    //     width: 70px;
    // height: 40px;
    border-radius: 200rpx;
    opacity: 1;
    padding: 24rpx 38rpx;
    background: #F8D247;

    font-size: 32rpx;
    font-weight: 600;

    color: rgba(0, 0, 0, 0.85);
}
</style>